package com.doit.hbase.client;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Table;

import java.io.IOException;

/**
 * @DATE 2021/12/13/10:40
 * @Author MDK
 * @Version 2021.2.2
 **/
public class C02_Insert {
    public static void main(String[] args) throws Exception {
        Configuration conf = HBaseConfiguration.create();
        conf.set("hbase.zookeeper.quorum","linux01:2181,linux02:2181,linux03:2181");
        Connection conn = ConnectionFactory.createConnection(conf);

        //获取操作的核心对象
        Table table = conn.getTable(TableName.valueOf("tb_teacher"));
        Put insert = new Put("rk002".getBytes());

        /*  插入的数据包括
        * 参数一  列族
        * 参数二  属性
        * 参数三   值
        * */
        insert.addColumn("cf".getBytes(),"name".getBytes(),"zss".getBytes());
//        insert.addColumn("cf".getBytes(),"age".getBytes(),"28".getBytes());
        insert.addColumn("cf".getBytes(),"age".getBytes(),"23".getBytes());
        insert.addColumn("cf".getBytes(),"gender".getBytes(),"female".getBytes());
        insert.addColumn("cf".getBytes(),"city".getBytes(),"bj".getBytes());
        table.put(insert);

        //释放资源
        table.close();
        conn.close();
    }
}
